package com.zhuss.team.processor;

import com.zhuss.bean.bo.team.information.ViewInfoSonBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.team.db.dao.ext.InformationSonDao;
import com.zhuss.team.db.entity.InformationSon;
import com.zhuss.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: zhushanshuo
 * @Date: 2020/3/25 14:27
 */
@Component("informationSonView")
public class InformationSonView extends AbstractProcessor<Object, ViewInfoSonBo> implements Processor<Object, ViewInfoSonBo> {

    @Autowired
    private InformationSonDao informationSonDao;

    @Override
    public Object process(ViewInfoSonBo bo) throws WpsException {
        InformationSon son = new InformationSon();
        son.setSonId(bo.getSonId());
        son.setStatus(bo.getStatus());
        informationSonDao.updateByPrimaryKeySelective(son);
        return null;
    }

    @Override
    public Object log(ViewInfoSonBo param) throws WpsException {
        OpLog record = new OpLog();
        record.setMoudle(MoudleEnum.协同发布.key());
        record.setAction(LogActionEnum.信息发布待阅信息查看.key());
        record.setTargetId(param.getSonId());
        record.setContent("参数: " + JsonUtil.toJson(param));
        record.setReason(param.getExceptionReason());

        record.setCreatorId(param.getConcurrentUserId());
        record.setCreator(param.getConcurrentUserName());
        record.setCreateTime(new Date());
        log(record);
        return null;
    }

    @Override
    public void check(ViewInfoSonBo viewInfoSonBo) throws WpsException {

    }
}
